<?php
namespace app\controller;

use think\facade\Db;
use think\facade\View;

class User extends Base{
    public function info(){
        $actives = Db::table('active_school')->select()->toArray();
        View::assign([
            'actives'=>$actives
        ]);
        return View::fetch();
    }

    public function download(){
        $id = intval(input('get.id',1));
        if(empty($id)){
            return_json(1,'下载失败,稍后再试');
        }
        $school = Db::table('active_school')->where('id',$id)->find();
        $users = Db::table('active_user')->where('act_sch_id',$id)->select();

        header("Content-type:application/vnd.ms-excel");
        header("Content-Disposition:filename=".$school['school_name']. date('Y-m-d') . ".xls");

        echo "姓名\t";
        echo "手机号\t\n";

        foreach ($users as $key => $value) {
            echo $value['realname'] . "\t";
            echo $value['mobile'] . "\t\n";
        }
        die();
    }
}
